package com.gurun.codes.views.bind_adapter;

import android.databinding.BindingAdapter;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.gurun.codes.R;

public class TextViewBindingAdapter {

    @BindingAdapter({"textcolor"})
    public static void setTextColor(TextView view, boolean isFirstItem) {
        if (view != null) {
            if (isFirstItem) {
                view.setTextColor(Color.parseColor("#fff728"));
            } else {
                view.setTextColor(Color.parseColor("#ffffff"));
            }
        }
    }

    @BindingAdapter({"onlineStatus","onalarmTextcolor"})
    public static void setonlinestatus(TextView view, String status,int alarmFlag) {
        if (view != null) {
            if ("设备离线".equals(status)) {
                view.setText(R.string.common_offline);
                view.setTextColor(view.getContext().getResources().getColor(R.color.home_device_offline_color));
            } else {
                view.setText(R.string.common_online);
                view.setTextColor(view.getContext().getResources().getColor(R.color.white));
            }

            if (alarmFlag == 1) {
                view.setTextColor(view.getContext().getResources().getColor(R.color.red));
            }
        }
    }

    @BindingAdapter({"visibility"})
    public static void setVisibility(TextView view, String description) {
        if (view != null) {
            if (TextUtils.isEmpty(description.trim())){
                view.setVisibility(View.GONE);
            }else{
                view.setVisibility(View.VISIBLE);
            }
        }
    }


    @BindingAdapter({"onalarmContentTextcolor"})
    public static void setonalarmContentTextcolor(TextView view,int alarmFlag) {
        if (view != null) {
            if (alarmFlag == 1) {
                view.setTextColor(view.getContext().getResources().getColor(R.color.alarm_content_alarm));
            }else{
                view.setTextColor(view.getContext().getResources().getColor(R.color.alarm_content_normal));
            }
        }
    }
}
